package ads.util;

import java.util.ArrayList;
import java.util.List;

public class GameInfo implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6255108013386843852L;
	private Integer id;
	private Integer countOfPlayer;
	private ArrayList<PlayerInfo> players;

	public GameInfo() {
		super();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getCountOfPlayer() {
		return countOfPlayer;
	}

	public void setCountOfPlayer(Integer countOfPlayer) {
		this.countOfPlayer = countOfPlayer;
	}

	public ArrayList<PlayerInfo> getPlayers() {
		return players;
	}

	public void setPlayers(ArrayList<PlayerInfo> players) {
		this.players = players;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (obj instanceof GameInfo) {
			GameInfo o = (GameInfo) obj;
			if (this.getId().equals(o.getId())) {
				return true;
			}
		}
		return false;
	}

	@Override
	public String toString() {
		String text = "game ID:" + this.getId() + ", maximal player:"
				+ this.getCountOfPlayer() + ",Player:" + this.getPlayers();
		return text;
	}

	public boolean hasPlayer(PlayerInfo pi) {
		return players.contains(pi);
	}

	public void updatePlayer(PlayerInfo pi) {
		if (players.contains(pi)) {
			players.remove(pi);
			players.add(pi);
		}

	}

	public boolean isFull() {
		return this.countOfPlayer != null && this.players != null
				&& countOfPlayer == this.players.size();
	}
}
